package com.example.bnuzzu.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.bnuzzu.common.dto.FavoriteDto;
import com.example.bnuzzu.common.dto.HouseListDto;
import com.example.bnuzzu.entity.Favoritehouse;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author BNUZZU
 * @since 2021-04-13
 */
@Repository
public interface FavoritehouseMapper extends BaseMapper<Favoritehouse> {
    /**
     * 收藏分页查询
     * @param page 分页数据
     * @param userid 用户id
     * @return 带数据的分页数据
     */
    @Select("SELECT fa.*,house.HouseName,house.UserID as OwnerID,(SELECT UserName FROM userinfo WHERE UserID = OwnerID) as OwnerName " +
            "FROM favoritehouse fa,houseinfo house,userinfo users " +
            "WHERE fa.HouseID = house.HouseID AND users.UserID = fa.UserID AND fa.UserID = #{userid}")
    IPage<FavoriteDto> selectPageVo(Page<?> page, Integer userid);
}
